local shouzhen = fk.CreateSkill({
    name = "sj7__shouzhen",
})

Fk:loadTranslationTable{
  ["sj7__shouzhen"] = "守真",
  [":sj7__shouzhen"] = "你可将你的判定结果改为你上次的判定结果。",

  ["@sj7__shouzhen"] = "守真",
  ["#sj7__shouzhen"] = "守真：你可以将判定结果改为 %arg",

  ["$sj7__shouzhen1"] = "临别教诲，均谨记在心。",
}

local function toLogString(card)
  local ret = string.format('<font color="#0598BC"><b>%s</b></font>', Fk:translate(card.name) .. "[")
  if card:isVirtual() and #card.subcards ~= 1 then
    ret = ret .. Fk:translate(card:getColorString())
  else
    ret = ret .. Fk:translate("log_" .. card:getSuitString())
    if card.number > 0 then
      ret = ret .. string.format('<font color="%s"><b>%s</b></font>', card.color == Card.Red and "#CC3131" or "#FFFFFF", card:getNumberStr(card.number))
    end
  end
  ret = ret .. '<font color="#0598BC"><b>]</b></font>'
  return ret
end

shouzhen:addEffect(fk.AskForRetrial, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(shouzhen.name) and player:getMark("sj7__shouzhen") > 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player,{skill_name = shouzhen.name,prompt = "#sj7__shouzhen:::"..player:getMark("@sj7__shouzhen")})
  end,
  on_use = function(self, event, target, player, data)
    player.room:changeJudge{
      card = Fk:getCardById(player:getMark("sj7__shouzhen")),
      player = player,
      data = data,
      skillName = shouzhen.name,
    }
  end,
})

shouzhen:addEffect(fk.FinishJudge, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(shouzhen.name)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player,"sj7__shouzhen",data.card.id)
    player.room:setPlayerMark(player,"@sj7__shouzhen",toLogString(data.card))
  end,
})

shouzhen.onAcquire = function (self, player, is_start)
  player.room.logic:getEventsByRule(GameEvent.Judge, 1, function (e)
    if e.data.who == player then
      player.room:setPlayerMark(player,"sj7__shouzhen",e.data.card.id)
      player.room:setPlayerMark(player,"@sj7__shouzhen",toLogString(e.data.card))
      return true
    end
  end, 1)
end
shouzhen.onLose = function (self, player, is_start)
  player.room:setPlayerMark(player,"sj7__shouzhen",0)
  player.room:setPlayerMark(player,"@sj7__shouzhen",0)
end


return shouzhen